#!/usr/bin/perl -w

open(IN,"$ARGV[0]")||die"can not open $ARGV[0]soap outputfile";
open(IN1,"$ARGV[1]")||die"can not open $ARGV[1]soap outputfile";
open(OUT,">$ARGV[2]");
use strict;
my $seed=$ARGV[3];
my (%bs,%com,%info,%hit1,%hit2,%hit3,%infoe);

my $c=0;
while(<IN>)
{	
	if($_=~/chr/){
		my @a=split(/\s+/,$_);
		for(my $i=int($a[1]-$seed);$i<int($a[2]+$seed);$i++)
		{
			my $key=$a[0]."-".$i;
			$bs{$key}=1;
			$info{$key}=$a[0]."-".$a[1]."-".$a[2];
		}
		$c++;
	}
}
#print $ARGV[0],"---> total $c\t bindingsite;\n";
my $c2=0;my $com=0;
while(<IN1>)
{	
	if($_=~/chr/){
	my @a=split(/\s+/,$_);
	for(my $i=int($a[1]);$i<int($a[2]);$i++)
	{
			my $key=$a[0]."-".$i;
			if(defined $bs{$key})
			{
				$com++;
				
				print OUT $info{$key},"\t",$_;
				last;
				
			}
		
	}
	$c2++;
}
}

#print $ARGV[1],"---> total $c2\t bindingsite;\n";
#print "common bs in $seed\t$com\n";
my $s;
if($c>$c2){$s=$c2;}
else{$s=$c;}
print OUT $com,"(",$com*100/$s,")\n";
print  $com,"(",$com*100/$s,")\t";
